package com.ruoyi.framework.config;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.util.TimeZone;

/**
 * 程序注解配置
 *
 * @author ruoyi
 */
@Configuration
// 表示通过aop框架暴露该代理对象,AopContext能够访问
@EnableAspectJAutoProxy(exposeProxy = true)
// 指定要扫描的Mapper类的包的路径
@MapperScan({"com.ruoyi.**.mapper"})
public class ApplicationConfig {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder
                //Jackson全局转化Long类型为String，解决js精度丢失问题
                .serializerByType(Long.class, ToStringSerializer.instance)
                .serializerByType(Long[].class, LongArrayToStringArraySerializer.instance)
                //只对Long和Long[]进行转换，如果想long也生效，则解开此注释
//                .serializerByType(Long.TYPE, ToStringSerializer.instance)
                .serializers()
                //时区配置
                .timeZone(TimeZone.getDefault());
    }

}
